#include<at89x52.h>
int numstr[16]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};
//int str[8]={0x7f,0xbf,0xdf,0xef,0xf7,0xfd,0xfb,0xfe};
void Delay()
{
unsigned int a;
for(a=4000;a>0;a--)
  {
   }
}
unsigned char x=0,y=0;
unsigned char scankey()
{

	unsigned char  sum=0X10;
	unsigned char keydata=0;
	P2=0Xf0;
	Delay();
	keydata=P2;
	keydata=keydata&0xf0;
	if(	keydata==0xf0)
	{
	}
	else
	{
	    if(	keydata==0xe0)
 	    {
	        x=0;
  	    }
	    else
	    if(	keydata==0xd0) 
	    {
	        x=1;
	    }
	    else
	    if(	keydata==0xb0)
	    {
	        x=2;
	    }
	    else
	    if(	keydata==0x70)
	    {
	        x=3;
	    }
	    P2=0x0f;
		Delay();
		keydata=P2;
	    keydata=keydata&0x0f;
	    if(keydata==0x0e)
	    {
	        y=3;
	    }
	    else
	    if(keydata==0x0d)
	    {
	        y=2;
	    }
	    else
	    if(keydata==0x0b)
	    {
	        y=1;
	    }
	    else
	    if(keydata==0x07)
	    {
	        y=0;
	    }
        sum=4*y+x;
    }
	return(sum); 
}
void main()
{
	unsigned char t;
	while(1)
	{
	    t=scankey();
	    P1=0x7f;
	    if(t<0x10)
	    {
  	        P0=numstr[t];
	    }
	}
}